.class public Lrexsee/network/SocketClient;
.super Ljava/lang/Thread;
.source "SocketClient.java"


# instance fields
.field private final mClientId:Ljava/lang/String;

.field private final mLocalInetSocketAddress:Ljava/net/InetSocketAddress;

.field private mOnConnected:Lrexsee/network/SocketAbstractClass$SocketConnectedListener;

.field private mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

.field private mOnLost:Lrexsee/network/SocketAbstractClass$SocketLostListener;

.field private mOnRead:Lrexsee/network/SocketAbstractClass$SocketDataListener;

.field private mOnStarted:Lrexsee/network/SocketAbstractClass$SocketStartedListener;

.field private mOnWrite:Lrexsee/network/SocketAbstractClass$SocketDataListener;

.field private final mReadingCycle:I

.field private mReadingThread:Ljava/lang/Thread;

.field private final mRemoteInetSocketAddress:Ljava/net/InetSocketAddress;

.field private mSocket:Ljava/net/Socket;

.field private final mTimeout:I


# direct methods
.method public constructor <init>(Ljava/lang/String;Ljava/net/InetSocketAddress;Ljava/net/InetSocketAddress;II)V
    .locals 1
    .param p1, "clientId"    # Ljava/lang/String;
    .param p2, "localInetSocketAddress"    # Ljava/net/InetSocketAddress;
    .param p3, "remoteInetSocketAddress"    # Ljava/net/InetSocketAddress;
    .param p4, "timeout"    # I
    .param p5, "readingCycle"    # I

    .prologue
    const/4 v0, 0x0

    .line 31
    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    .line 21
    iput-object v0, p0, Lrexsee/network/SocketClient;->mOnStarted:Lrexsee/network/SocketAbstractClass$SocketStartedListener;

    .line 22
    iput-object v0, p0, Lrexsee/network/SocketClient;->mOnConnected:Lrexsee/network/SocketAbstractClass$SocketConnectedListener;

    .line 23
    iput-object v0, p0, Lrexsee/network/SocketClient;->mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

    .line 24
    iput-object v0, p0, Lrexsee/network/SocketClient;->mOnLost:Lrexsee/network/SocketAbstractClass$SocketLostListener;

    .line 25
    iput-object v0, p0, Lrexsee/network/SocketClient;->mOnRead:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    .line 26
    iput-object v0, p0, Lrexsee/network/SocketClient;->mOnWrite:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    .line 27
    iput-object v0, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    .line 28
    iput-object v0, p0, Lrexsee/network/SocketClient;->mReadingThread:Ljava/lang/Thread;

    .line 32
    iput-object p1, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    .line 33
    iput-object p2, p0, Lrexsee/network/SocketClient;->mLocalInetSocketAddress:Ljava/net/InetSocketAddress;

    .line 34
    iput-object p3, p0, Lrexsee/network/SocketClient;->mRemoteInetSocketAddress:Ljava/net/InetSocketAddress;

    .line 35
    iput p4, p0, Lrexsee/network/SocketClient;->mTimeout:I

    .line 36
    iput p5, p0, Lrexsee/network/SocketClient;->mReadingCycle:I

    .line 37
    return-void
.end method

.method static synthetic access$0(Lrexsee/network/SocketClient;)Ljava/net/Socket;
    .locals 1

    .prologue
    .line 27
    iget-object v0, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    return-object v0
.end method

.method static synthetic access$1(Lrexsee/network/SocketClient;)I
    .locals 1

    .prologue
    .line 20
    iget v0, p0, Lrexsee/network/SocketClient;->mReadingCycle:I

    return v0
.end method

.method static synthetic access$2(Lrexsee/network/SocketClient;)Lrexsee/network/SocketAbstractClass$SocketDataListener;
    .locals 1

    .prologue
    .line 25
    iget-object v0, p0, Lrexsee/network/SocketClient;->mOnRead:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    return-object v0
.end method

.method static synthetic access$3(Lrexsee/network/SocketClient;)Ljava/lang/String;
    .locals 1

    .prologue
    .line 16
    iget-object v0, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    return-object v0
.end method

.method static synthetic access$4(Lrexsee/network/SocketClient;)Lrexsee/network/SocketAbstractClass$SocketLostListener;
    .locals 1

    .prologue
    .line 24
    iget-object v0, p0, Lrexsee/network/SocketClient;->mOnLost:Lrexsee/network/SocketAbstractClass$SocketLostListener;

    return-object v0
.end method


# virtual methods
.method public close()V
    .locals 2

    .prologue
    const/4 v1, 0x0

    .line 122
    iput-object v1, p0, Lrexsee/network/SocketClient;->mReadingThread:Ljava/lang/Thread;

    .line 124
    :try_start_0
    iget-object v0, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    invoke-virtual {v0}, Ljava/net/Socket;->close()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 127
    :goto_0
    iput-object v1, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    .line 128
    return-void

    .line 125
    :catch_0
    move-exception v0

    goto :goto_0
.end method

.method public getClientId()Ljava/lang/String;
    .locals 1

    .prologue
    .line 107
    iget-object v0, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    return-object v0
.end method

.method public getLocalInetSocketAddress()Ljava/net/InetSocketAddress;
    .locals 1

    .prologue
    .line 113
    iget-object v0, p0, Lrexsee/network/SocketClient;->mLocalInetSocketAddress:Ljava/net/InetSocketAddress;

    return-object v0
.end method

.method public getRemoteInetSocketAddress()Ljava/net/InetSocketAddress;
    .locals 1

    .prologue
    .line 116
    iget-object v0, p0, Lrexsee/network/SocketClient;->mRemoteInetSocketAddress:Ljava/net/InetSocketAddress;

    return-object v0
.end method

.method public getSocket()Ljava/net/Socket;
    .locals 1

    .prologue
    .line 110
    iget-object v0, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    return-object v0
.end method

.method public getTimeout()I
    .locals 1

    .prologue
    .line 119
    iget v0, p0, Lrexsee/network/SocketClient;->mTimeout:I

    return v0
.end method

.method public isConnected()Z
    .locals 1

    .prologue
    .line 104
    iget-object v0, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    invoke-virtual {v0}, Ljava/net/Socket;->isConnected()Z

    move-result v0

    return v0
.end method

.method public isHealthy()Z
    .locals 1

    .prologue
    .line 101
    iget-object v0, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    if-nez v0, :cond_0

    const/4 v0, 0x0

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x1

    goto :goto_0
.end method

.method public run()V
    .locals 6

    .prologue
    const/4 v5, 0x0

    .line 42
    :try_start_0
    new-instance v1, Ljava/net/Socket;

    invoke-direct {v1}, Ljava/net/Socket;-><init>()V

    iput-object v1, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    .line 43
    iget-object v1, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    iget-object v2, p0, Lrexsee/network/SocketClient;->mLocalInetSocketAddress:Ljava/net/InetSocketAddress;

    invoke-virtual {v1, v2}, Ljava/net/Socket;->bind(Ljava/net/SocketAddress;)V

    .line 44
    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnStarted:Lrexsee/network/SocketAbstractClass$SocketStartedListener;

    if-eqz v1, :cond_0

    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnStarted:Lrexsee/network/SocketAbstractClass$SocketStartedListener;

    iget-object v2, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    const/4 v3, 0x0

    invoke-virtual {v1, v2, v3}, Lrexsee/network/SocketAbstractClass$SocketStartedListener;->run(Ljava/lang/String;Z)V

    .line 45
    :cond_0
    iget-object v1, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    iget-object v2, p0, Lrexsee/network/SocketClient;->mRemoteInetSocketAddress:Ljava/net/InetSocketAddress;

    iget v3, p0, Lrexsee/network/SocketClient;->mTimeout:I

    invoke-virtual {v1, v2, v3}, Ljava/net/Socket;->connect(Ljava/net/SocketAddress;I)V

    .line 46
    iget-object v1, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    if-eqz v1, :cond_2

    iget-object v1, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    invoke-virtual {v1}, Ljava/net/Socket;->isConnected()Z

    move-result v1

    if-eqz v1, :cond_2

    .line 47
    new-instance v1, Lrexsee/network/SocketClient$1;

    invoke-direct {v1, p0}, Lrexsee/network/SocketClient$1;-><init>(Lrexsee/network/SocketClient;)V

    iput-object v1, p0, Lrexsee/network/SocketClient;->mReadingThread:Ljava/lang/Thread;

    .line 72
    iget-object v1, p0, Lrexsee/network/SocketClient;->mReadingThread:Ljava/lang/Thread;

    invoke-virtual {v1}, Ljava/lang/Thread;->start()V

    .line 73
    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnConnected:Lrexsee/network/SocketAbstractClass$SocketConnectedListener;

    if-eqz v1, :cond_1

    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnConnected:Lrexsee/network/SocketAbstractClass$SocketConnectedListener;

    iget-object v2, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    const-wide/16 v3, -0x1

    invoke-virtual {v1, v2, v3, v4}, Lrexsee/network/SocketAbstractClass$SocketConnectedListener;->run(Ljava/lang/String;J)V

    .line 82
    :cond_1
    :goto_0
    return-void

    .line 75
    :cond_2
    invoke-virtual {p0}, Lrexsee/network/SocketClient;->close()V

    .line 76
    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

    if-eqz v1, :cond_1

    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

    iget-object v2, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    const/4 v3, 0x0

    const-string v4, "Timeout."

    invoke-virtual {v1, v2, v3, v4}, Lrexsee/network/SocketAbstractClass$SocketFailedListener;->run(Ljava/lang/String;ZLjava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 78
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 79
    .local v0, "e":Ljava/lang/Exception;
    invoke-virtual {p0}, Lrexsee/network/SocketClient;->close()V

    .line 80
    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

    if-eqz v1, :cond_1

    iget-object v1, p0, Lrexsee/network/SocketClient;->mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

    iget-object v2, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    invoke-virtual {v0}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v1, v2, v5, v3}, Lrexsee/network/SocketAbstractClass$SocketFailedListener;->run(Ljava/lang/String;ZLjava/lang/String;)V

    goto :goto_0
.end method

.method public setListeners(Lrexsee/network/SocketAbstractClass$SocketStartedListener;Lrexsee/network/SocketAbstractClass$SocketFailedListener;Lrexsee/network/SocketAbstractClass$SocketConnectedListener;Lrexsee/network/SocketAbstractClass$SocketLostListener;Lrexsee/network/SocketAbstractClass$SocketDataListener;Lrexsee/network/SocketAbstractClass$SocketDataListener;)V
    .locals 0
    .param p1, "started"    # Lrexsee/network/SocketAbstractClass$SocketStartedListener;
    .param p2, "failed"    # Lrexsee/network/SocketAbstractClass$SocketFailedListener;
    .param p3, "connected"    # Lrexsee/network/SocketAbstractClass$SocketConnectedListener;
    .param p4, "lost"    # Lrexsee/network/SocketAbstractClass$SocketLostListener;
    .param p5, "read"    # Lrexsee/network/SocketAbstractClass$SocketDataListener;
    .param p6, "write"    # Lrexsee/network/SocketAbstractClass$SocketDataListener;

    .prologue
    .line 92
    iput-object p1, p0, Lrexsee/network/SocketClient;->mOnStarted:Lrexsee/network/SocketAbstractClass$SocketStartedListener;

    .line 93
    iput-object p2, p0, Lrexsee/network/SocketClient;->mOnFailed:Lrexsee/network/SocketAbstractClass$SocketFailedListener;

    .line 94
    iput-object p3, p0, Lrexsee/network/SocketClient;->mOnConnected:Lrexsee/network/SocketAbstractClass$SocketConnectedListener;

    .line 95
    iput-object p4, p0, Lrexsee/network/SocketClient;->mOnLost:Lrexsee/network/SocketAbstractClass$SocketLostListener;

    .line 96
    iput-object p5, p0, Lrexsee/network/SocketClient;->mOnRead:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    .line 97
    iput-object p6, p0, Lrexsee/network/SocketClient;->mOnWrite:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    .line 98
    return-void
.end method

.method public write([B)Z
    .locals 9
    .param p1, "bytes"    # [B

    .prologue
    const-wide/16 v7, -0x1

    const/4 v6, 0x0

    .line 131
    iget-object v2, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    if-nez v2, :cond_0

    move v2, v6

    .line 140
    :goto_0
    return v2

    .line 133
    :cond_0
    :try_start_0
    iget-object v2, p0, Lrexsee/network/SocketClient;->mSocket:Ljava/net/Socket;

    invoke-virtual {v2}, Ljava/net/Socket;->getOutputStream()Ljava/io/OutputStream;

    move-result-object v1

    .line 134
    .local v1, "outputStream":Ljava/io/OutputStream;
    invoke-virtual {v1, p1}, Ljava/io/OutputStream;->write([B)V

    .line 135
    iget-object v2, p0, Lrexsee/network/SocketClient;->mOnWrite:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    if-eqz v2, :cond_1

    iget-object v2, p0, Lrexsee/network/SocketClient;->mOnWrite:Lrexsee/network/SocketAbstractClass$SocketDataListener;

    iget-object v3, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    const-wide/16 v4, -0x1

    invoke-virtual {v2, v3, v4, v5, p1}, Lrexsee/network/SocketAbstractClass$SocketDataListener;->run(Ljava/lang/String;J[B)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 136
    :cond_1
    const/4 v2, 0x1

    goto :goto_0

    .line 137
    .end local v1    # "outputStream":Ljava/io/OutputStream;
    :catch_0
    move-exception v2

    move-object v0, v2

    .line 138
    .local v0, "e":Ljava/lang/Exception;
    invoke-virtual {p0}, Lrexsee/network/SocketClient;->close()V

    .line 139
    iget-object v2, p0, Lrexsee/network/SocketClient;->mOnLost:Lrexsee/network/SocketAbstractClass$SocketLostListener;

    if-eqz v2, :cond_2

    iget-object v2, p0, Lrexsee/network/SocketClient;->mOnLost:Lrexsee/network/SocketAbstractClass$SocketLostListener;

    iget-object v3, p0, Lrexsee/network/SocketClient;->mClientId:Ljava/lang/String;

    invoke-virtual {v0}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v2, v3, v7, v8, v4}, Lrexsee/network/SocketAbstractClass$SocketLostListener;->run(Ljava/lang/String;JLjava/lang/String;)V

    :cond_2
    move v2, v6

    .line 140
    goto :goto_0
.end method
